Q = require 'q'

defer1 = Q.defer()

defer1.reject('resolve')

promise1 = defer1.promise

defer2 = Q.defer()

defer2.resolve('resolve')

promise2 = defer2.promise


createPromise = (i)->

  defer=Q.defer()
  setTimeout (()->
    console.log 'func'+i+' end'
    defer.resolve 'success'
    return defer.promise
  ),5000


func1=()->
  console.log 'func1 start'

  return createPromise 1
func2=()->
  console.log 'func2********start'
  return createPromise 2
promise2.then func1
  .done func2
